﻿using System;
using System.Data.OleDb;
using System.Windows.Forms;


namespace Texpro
{
    public partial class FMMN201 : Form
    {
        public FMMN201()
        {
            InitializeComponent();
        }

        private void wf_popup_Load(object sender, EventArgs e)
        {
            PCPUB.m_popup_result_text = String.Empty;
            txt_SEARCH.Text = PCPUB.m_popup_search_text.ToString();
            GetPopupList();
        }

        private void GetPopupList()
        {
            String strQuery = String.Empty;
            OleDbConnection sqlConn = new OleDbConnection();
            OleDbCommand sqlComm = new OleDbCommand();
            OleDbDataReader sqlRead;
            //
            lb_POPUP.Items.Clear();
            switch (PCPUB.m_popup_search_type.ToString())
            {
                //case "DEALER_NAME":
                //    strQuery = String.Empty;
                //    strQuery += " SELECT DISTINCT [DEALER]";
                //    strQuery += " FROM [CAF_MASTER] ";
                //    strQuery += " WHERE [DEALER] <> '' ";
                //    if (clsPub.m_popup_search_text.Length > 0)
                //        strQuery += " AND [DEALER] LIKE '" + clsPub.m_popup_search_text.ToString() + "%'" ;
                //    strQuery += " ORDER BY [DEALER]";
                //break;
                //case "CITY_NAME":
                //    strQuery = String.Empty;
                //    strQuery += " SELECT DISTINCT [CITY]";
                //    strQuery += " FROM [CAF_MASTER] ";
                //    strQuery += " WHERE [CITY] <> '' ";
                //    if (clsPub.m_popup_search_text.Length > 0)
                //        strQuery += " AND [CITY] LIKE '" + clsPub.m_popup_search_text.ToString() + "%'";
                //    strQuery += " ORDER BY [CITY]";
                //break;

                case "YARN_VENDOR":
                    strQuery += " SELECT [vendor_id],[vendor_name]";
                    strQuery += " FROM [tis_vendor] ";
                    strQuery += " WHERE [vendor_type_id] = 'YARN_VEND'";
                    if (PCPUB.m_popup_search_text.Length > 0)
                        strQuery += " AND [vendor_name] LIKE '" + PCPUB.m_popup_search_text.ToString() + "%'";
                    strQuery += " ORDER BY [vendor_name]";
                    break;
                case "YARN_BUYER":
                    strQuery += " SELECT [vendor_id],[vendor_name]";
                    strQuery += " FROM [tis_vendor] ";
                    strQuery += " WHERE [vendor_type_id] = 'YARN_CUST'";
                    if (PCPUB.m_popup_search_text.Length > 0)
                        strQuery += " AND [vendor_name] LIKE '" + PCPUB.m_popup_search_text.ToString() + "%'";
                    strQuery += " ORDER BY [vendor_name]";
                    break;
                case "YARN_COUNT":
                    strQuery += " SELECT [yarn_count_id],[yarn_count_name]";
                    strQuery += " FROM [tis_yarn_count] ";
                    if (PCPUB.m_popup_search_text.Length > 0)
                        strQuery += " AND [yarn_count_name] LIKE '" + PCPUB.m_popup_search_text.ToString() + "%'";
                    strQuery += " ORDER BY [yarn_count_name]";
                    break;
                case "color":
                    strQuery += " SELECT [color_id],[color_name]";
                    strQuery += " FROM [tis_color] ";
                    if (PCPUB.m_popup_search_text.Length > 0)
                        strQuery += " AND [color_name] LIKE '" + PCPUB.m_popup_search_text.ToString() + "%'";
                    strQuery += " ORDER BY [color_name]";
                    break;

            }
            sqlConn.ConnectionString = PCPUB.m_oledb_connection.ToString();
            sqlConn.Open();
            sqlComm.Connection = sqlConn;
            sqlComm.CommandText = strQuery.ToString();
            sqlRead = sqlComm.ExecuteReader();
            while (sqlRead.Read())
            {
                lb_POPUP.Items.Add(sqlRead[0].ToString());
            }
            sqlRead.Close();
            sqlConn.Close();
        }

        private void but_SEARCH_Click(object sender, EventArgs e)
        {
            PCPUB.m_popup_search_text = txt_SEARCH.Text.Trim();
            GetPopupList();
        }

        private void bu_OK_Click(object sender, EventArgs e)
        {
            PCPUB.m_popup_result_text = String.Empty;
            if (lb_POPUP.SelectedItem != null)
            PCPUB.m_popup_result_text = lb_POPUP.SelectedItem.ToString();
            this.Close();
        }

        private void but_CANCEL_Click(object sender, EventArgs e)
        {
            PCPUB.m_popup_result_text = String.Empty;
            this.Close();
        }

        private void lb_POPUP_DoubleClick(object sender, EventArgs e)
        {
            bu_OK_Click(sender,e);
        }
    }
}
